package pruebas.testUtil;

import org.junit.*;
import static org.junit.Assert.*;
import modelo.util.Vector;

public class TestVector{
	
	Vector v0 = new Vector(0,0);	
	Vector v1 = new Vector(3,4);
	Vector v2 = new Vector(4,3);
	Vector v3 = new Vector(1,0);
	Vector v4 = new Vector(0,1);
	Vector v5 = new Vector(1,1);
	Vector v6 = new Vector(-1,1);
	Vector v7 = new Vector(7,7);	
	Vector v8 = new Vector(-1,0);		
	
	Vector r1;
	
	@Test
	public void testGet(){
		assertEquals(v0.getx(), (float) 0 , 0);
		assertEquals(v0.gety(), (float) 0, 0);
		assertEquals(v1.getx(), (float) 3, 0);
		assertEquals(v1.gety(), (float) 4, 0);
	}

	@Test
	public void testSuma() {
		assertEquals("(3,4) = (3,4)+(0,0)", v1 , v1.sumar(v0) );
		r1 = v1.sumar(v2); // r1 = (3,4)+(4,3) = (7,7)
		assertEquals(r1.getx(), (float) 7, 0.0001);
		assertEquals(r1.gety(), (float) 7, 0.0001);
	}
	
	@Test
	public void testResta() {
		r1 = v1.restar(v2); // r1 = (3,4)-(4,3) = (-1,1)
		assertEquals(r1.getx(), (float) -1, 0.0001);
		assertEquals(r1.gety(), (float) 1, 0.0001);
		assertEquals(r1 , (v6) );
	}
	
	@Test
	public void testMultiplicar() {
		r1 = v5.multiplicar(7);
		assertEquals(r1.getx(), (float) 7, 0.0001);
		assertEquals(r1.gety(), (float) 7, 0.0001);
		r1 = v5.multiplicar(0);
		assertEquals(r1.getx(), (float) 0, 0.0001);
		assertEquals(r1.gety(), (float) 0, 0.0001);
	}
	
	@Test
	public void testDividir() {
		r1 = v7.dividir(7);
		assertEquals(r1.getx(), (float) 1, 0.0001);
		assertEquals(r1.gety(), (float) 1, 0.0001);
		try {
			r1 = v5.dividir(0);
			assertTrue(false);
		}
		catch(ArithmeticException er) {}
	}
	
	@Test
	public void testNorma() {
		assertEquals(v0.norma(), (float) 0, 0.0001);
		assertEquals(v1.norma(), (float) 5, 0.0001);
		assertEquals(v3.norma(), (float) 1, 0.0001);
		assertEquals(v5.norma(), v6.norma(), 0.0001);
	}
	
	@Test
	public void testVersor() {
		assertEquals(v3.versor() , (v3));
		assertEquals(v5.versor() , (v7.versor()));
	}
	
	@Test
	public void testDistancia() {
		assertEquals(v1.distancia(v0), (float) 5, 0.0001);
		assertEquals(v3.distancia(v5), (float) 1, 0.0001);
	}
	
	@Test
	public void testRotar() {
		assertEquals(v3.rotar(Math.PI/2), new Vector (0,1));
		assertEquals(v3.rotar(Math.PI), new Vector (-1,0));
		assertEquals(v3.rotar(-Math.PI), new Vector (-1,0));
		assertEquals(v5.rotar(Math.PI/4).versor(), new Vector (0,1));
	}

	@Test
	public void testAngulo() {
		assertEquals(v3.angulo(v4), Math.PI/2, 0.0001);
		assertEquals(v4.angulo(v3), -Math.PI/2, 0.0001);
		assertEquals(v3.angulo(v7), Math.PI/4, 0.0001);
		assertEquals(v5.angulo(v6), Math.PI/2, 0.0001);
		assertEquals(v3.angulo(v8), Math.PI, 0.0001);
	}
}
